package com.cy.gameserver.controller;

import com.cy.gameserver.webSockect.WebSocketDispatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by tiankai.qin on 18/3/13.
 */
@Controller
@RequestMapping("/test")
public class TestCtrl {

    private static final Logger logger = LoggerFactory.getLogger(TestCtrl.class);

    @Autowired
    private WebSocketDispatcher webSocketDispatcher;

    @RequestMapping("/browserWebsocket")
    public String index() {
        logger.info("有访问进来啦！");
        return "websocket-client";
    }

    @ResponseBody
    @RequestMapping("/getOnlineNum")
    public String getOnlineNum() {
        return String.valueOf(webSocketDispatcher.getOnlineNum());
    }

    @RequestMapping("/sendMsg")
    public void sendMsg(@RequestParam String token, @RequestParam String msg) {
        webSocketDispatcher.sendMessageByToken(token, msg);
    }

}
